{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ecfd703e",
   "metadata": {},
   "source": [
    "# MuZero Planning Demo – Colab\n",
    "Run the Alpha‑Factory **MuZero** illustration in one click. In ~60 s you’ll get a Gradio dashboard with live video and reward curves.\n",
    "\n",
    "*Optional:* set your **OpenAI API key** below for narrative commentary; otherwise the demo runs fully offline."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb0bb1be",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install core dependencies\n",
    "!pip -q install \"torch>=2.1\" gymnasium[classic-control] gradio openai_agents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "881ead00",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Clone Alpha‑Factory repository\n",
    "!git clone --depth 1 https://github.com/MontrealAI/AGI-Alpha-Agent-v0.git\n",
    "%cd AGI-Alpha-Agent-v0/alpha_factory_v1/demos/muzero_planning"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0afcf7b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 👉 OPTIONAL: set your OpenAI key for commentary\n",
    "# import os, getpass\n",
    "# os.environ[\"OPENAI_API_KEY\"] = getpass.getpass(prompt=\"Enter OpenAI API key: \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9874987f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Launch the MuZero Gradio dashboard (shared link will appear below)\n",
    "import os, subprocess, time, signal, sys, threading\n",
    "os.environ[\"GRADIO_SHARE\"] = \"1\"\n",
    "process = subprocess.Popen([sys.executable, \"agent_muzero_entrypoint.py\"])\n",
    "print(\"⌛ Booting… wait for the public URL ↴\")\n",
    "try:\n",
    "    while process.poll() is None:\n",
    "        time.sleep(5)\n",
    "except KeyboardInterrupt:\n",
    "    process.send_signal(signal.SIGINT)\n",
    "    process.wait()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.x"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
